/*
 * PURION_Produce.java
 *
 * Created on 2008년 1월 1일 (화), 오전 10:57
 */

package PuriON;

import java.awt.*;
import javax.swing.*;

/**
 *
 * @author  hyukmini
 */
public class PURION_Produce extends JDialog {
    
    PURION_Main parent = null;
    
    
    
    /** Creates new form PURION_Produce */
    public PURION_Produce(PURION_Main p, boolean modal) {
        
        /* 부모에 대한 모달 설정 */
        super(p, modal);
        parent = p;
        
        /* 컴포넌트들을 초기화 합니다. */
        this.initComponents();     
        
        this.setLocation(parent.getX() + parent.getWidth() / 2 - this.getWidth() / 2,
        this.parent.getY() + parent.getHeight() / 2 - this.getHeight() / 2); 

        this.setVisible(true);
    }
    
    public void sendQuery() {
        PURION_Connect listquery;
        
        String query = "INSERT INTO ShareList(user_id, ip, port) VALUES ('" + parent.loginid + "',";

        listquery = new PURION_Connect(parent);
        listquery.sendMessage(query);
        
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        nameLabel = new javax.swing.JLabel();
        nameText = new javax.swing.JTextField();
        listLabel = new javax.swing.JLabel();
        startButton = new javax.swing.JButton();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        nameText1 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        listLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("방송 개설");
        setResizable(false);

        nameLabel.setText("인터넷 스트리밍 방송의 제목을 입력합니다.");

        listLabel.setText("방 정보를 선택합니다.");

        startButton.setText("방송 개설");
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("비공개방");
        jRadioButton1.setBounds(110, 10, 80, 23);
        jLayeredPane1.add(jRadioButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("공개방");
        jRadioButton2.setBounds(20, 10, 61, 23);
        jLayeredPane1.add(jRadioButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        nameText1.setBounds(200, 10, 110, 21);
        jLayeredPane1.add(nameText1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "20명", "10명", "5명" }));

        listLabel1.setText("방송 제한 인원 수");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nameText, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                    .addComponent(nameLabel)
                    .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(listLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                        .addComponent(startButton))
                    .addComponent(listLabel))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(nameLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(listLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(listLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(startButton)))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
        // TODO add your handling code here:
        String title = nameText.getText();
        
        if(title.equals("")) {
           JOptionPane.showMessageDialog(this, "스트리밍 방 제목을 입력해 주세요.");
        }
        else {
            sendQuery();
            parent.startProducer(title);
            this.dispose();
        }
        
        //08.05.30 이진우 PURION_Connect 수정중 추가 부분
        //방만드는 메시지를 보낸다
        //형태는 MAKE|방제목|IP
        //정상 리턴값은 :ANS
        PURION_Connect sock = new PURION_Connect(parent);
        String message = "MAKE|" + nameText.getText() + "|" + sock.getMyIP();

        if (!sock.sendMessage(message).equals(":ANS")) {
            sock.showAlert("방만들기 실패");
        }
}//GEN-LAST:event_startButtonActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JLabel listLabel;
    private javax.swing.JLabel listLabel1;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameText;
    private javax.swing.JTextField nameText1;
    private javax.swing.JButton startButton;
    // End of variables declaration//GEN-END:variables
   
}
